package com.bss.dao;

// Generated Nov 1, 2011 10:54:22 PM by Hibernate Tools 3.3.0.GA

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.andy.basics.Dao;
import com.bss.model.Patient;
import com.bss.model.Room;

@Repository
public class RoomDao extends Dao<Room> {
	public Patient findCurrent(Room room) {
		Query q = this
				.getEntityManager()
				.createQuery(
						"Select p from Patient p join p.admissions as a join a.roomBookings as rb where rb.checkOutDate is null and rb.room.id =? ");
		q.setParameter(1, room.getId());
		List<Patient> patients = q.getResultList();
		return patients.get(0);
	}
}
